package im.yisme.model.remote;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

public class PostHandler {

	private static String URL = "http://www.yisme.im/cup/";
	public static String UPLOAD_SERVLET = "Upload";
	public static String UOLOADFILE_SERVLET = "UploadFile";
	public static String DOWNLOAD_SERVLET = "Download";
	public static String SEARCH_SERVLET = "Search";
	public static String EVALUATE_SERVLET = "Evaluate";
	
	public JSONObject post(HttpEntity entity, String servlet) throws IOException, JSONException{
		HttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost(URL + servlet);
		HttpResponse response;
		
		post.setEntity(entity);		
		response = client.execute(post);		
		
		String message = EntityUtils.toString(response.getEntity(),HTTP.UTF_8);
		JSONObject jsonObject = new JSONObject(message);
		return jsonObject;
	}
}
